
// TestApplicationDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TestApplication.h"
#include "TestApplicationDlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CTestApplicationDlg dialog




CTestApplicationDlg::CTestApplicationDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CTestApplicationDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestApplicationDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CTestApplicationDlg, CDialogEx)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDOK, &CTestApplicationDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BUTTON_SEND_TO_COM1, &CTestApplicationDlg::OnBnClickedButtonSendToCom1)
	ON_BN_CLICKED(IDC_BUTTON_WRITE_FILE, &CTestApplicationDlg::OnBnClickedButtonWriteFile)
END_MESSAGE_MAP()


// CTestApplicationDlg message handlers

BOOL CTestApplicationDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	LoadLibraryA("C:\\ComHook.dll");

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTestApplicationDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTestApplicationDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}



void CTestApplicationDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	CDialogEx::OnOK();
}


void CTestApplicationDlg::OnBnClickedButtonSendToCom1()
{
	DWORD dwWritten;
	HANDLE hCom = CreateFileA("COM1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
	WriteFile(hCom, "Hello World", sizeof("Hello World"), &dwWritten, NULL);
	CloseHandle(hCom);
}


void CTestApplicationDlg::OnBnClickedButtonWriteFile()
{
}
